package com.jjiang.bbmall.order.web;

import com.jjiang.bbmall.order.entity.OrderEntity;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.UUID;

@Controller
public class PageController {
    @Autowired
    RabbitTemplate rabbitTemplate;

    @GetMapping("/confirm.html")
    public String confirm() {
        return "confirm";
    }

    @GetMapping("/detail.html")
    public String detail() {
        return "detail";
    }

    @GetMapping("/pay.html")
    public String pay() {
        return "pay";
    }

    @GetMapping("/test/createOrder")
    @ResponseBody
    public OrderEntity createOrderTest() {
        // 模拟订单下单成功
        OrderEntity entity = new OrderEntity();
        entity.setOrderSn(UUID.randomUUID().toString());
        entity.setModifyTime(new Date());
        // 发送消息给MQ
        rabbitTemplate.convertAndSend("order-event-exchange", "order.create.order", entity);
        return entity;
    }
}
